/**
 * Created by fdg282 on 2017/8/7.
 */
function gohartAnimate(dom){
    var countSum = parseInt($("#hart-count").text());
    var goodsIcon = $(dom);
    var goodsOffset = goodsIcon.offset();
    var flyIcon = goodsIcon.clone();
    $('body').append(flyIcon);
    countSum++;
    $("#hart-count").text(countSum);
    var count = $('#hart-count').offset();
    flyIcon.css({ 'z-index': 9000,
        'display': 'block',
        'position': 'absolute',
        'top': goodsOffset.top +'px',
        'left': goodsOffset.left +'px',
        'width': goodsIcon.width() +'px',
        'height': goodsIcon.height() +'px'
    });
    flyIcon.animate({
        top: count.top,
        left: count.left,
        width: 10,
        height: 10
    }, 'slow',function(){
        flyIcon.remove()
    });
}

$(function(){
    //mod by FDG367 461 点击商品图片、国家图标、品牌、商品名称、系列名、价格，都能链接至商品详情页 2018-01-24 start
    $('#group_goods_list').find('span.icon_animation').on('click',function(){
        var goods_id = $(this).attr('data-goods-id');
        $.post('/goods/goods-collection',{goods_id:goods_id},function success(data){
            if(data.code == 500){
                window.location.href = data.url;
            }
            if(data.code == 200 || data.code == 202){
                var count = parseInt($("#hart-count").text());
                $('#group_goods_list').find('span.icon_animation').each(function(){
                    if($(this).attr('data-goods-id') == goods_id){
                        if($(this).is(".icon-hart-active")){
                            count--;
                            $(this).removeClass('icon-hart-active').addClass('icon-hart');
                            $("#hart-count").text(count);
                        }else {
                            $(this).removeClass('icon-hart').addClass('icon-hart-active');
                            gohartAnimate(this);
                        }
                    }
                });
            }
        },'json');
    });
    //mod by FDG367 461 点击商品图片、国家图标、品牌、商品名称、系列名、价格，都能链接至商品详情页 2018-01-24 end
});
